package POJO;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Entity
@Table(name = "CART")
@Component("cart")
@Scope("session")
public class Cart {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "Cart_Id")
	private int cartId;
	
	@Column(name = "Create_Date")
	private Date createDate;
	
	@Column(name = "Deleted")
	private int deleted;
	
	@ManyToOne()
	@JoinColumn(name = "Customer_Id")
	private Customer customer;
	
	@OneToMany(fetch = FetchType.EAGER, mappedBy="cart")
	@Fetch(FetchMode.SELECT)
    private Set<CartDetail> cartDetails = new HashSet<CartDetail>();
	

	public Cart() {
		this.createDate = new Date();
		this.deleted = 0;
	}
	public Cart(Date create_date, int deleted, Customer customer) {
		super();
		this.createDate = create_date;
		this.deleted = deleted;
		this.customer = customer;
	}
	
	public int getCartId() {
		return cartId;
	}
	public void setCartId(int cartId) {
		this.cartId = cartId;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public int getDeleted() {
		return deleted;
	}
	public void setDeleted(int deleted) {
		this.deleted = deleted;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public Set<CartDetail> getCartDetails() {
		return cartDetails;
	}
	public void setCartDetails(Set<CartDetail> cartDetails) {
		this.cartDetails = cartDetails;
	}
}
